package com.mc.read.pcApi.controller;

import com.mc.read.dao.models.BookinformationCustom;
import com.mc.read.pcApi.service.BookService;
import com.mc.read.vo.request.BaseRequest;
import com.mc.read.vo.respose.BaseRespose;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author:LiuHao
 * @Date:14:30 2019/5/30
 * 书籍controller
 **/
@Controller
@RequestMapping(value = "/verify/user/")
@Slf4j
public class BookController {
    @Autowired
    BookService bookService;

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 选择书籍类型 selectBookType
     **/
    @ResponseBody
    @RequestMapping(value = "selectBookType", method = RequestMethod.POST)
    public BaseRespose selectBookType(@RequestBody BaseRequest baseRequest) {
        BaseRespose baseRespose = bookService.selectBookType(baseRequest);
        return baseRespose;
    }


    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 前台用户添加书籍 userAddBook
     **/
    @ResponseBody
    @RequestMapping(value = "userAddBook", method = RequestMethod.POST)
    public BaseRespose userAddBook(@RequestBody BaseRequest baseRequest) {
        BaseRespose baseRespose = bookService.userAddBook(baseRequest);
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 查询我的历史记录 selectReadhistoryList
     **/
    @ResponseBody
    @RequestMapping(value = "selectReadhistoryList", method = RequestMethod.POST)
    public BaseRespose selectReadhistoryList(@RequestBody BaseRequest baseRequest) {
        BaseRespose baseRespose = bookService.selectReadhistoryList(baseRequest);
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 添加历史记录 addReadhistory
     **/
    @ResponseBody
    @RequestMapping(value = "addReadhistory", method = RequestMethod.POST)
    public BaseRespose addReadhistory(@RequestBody BaseRequest baseRequest) {
        BaseRespose baseRespose = bookService.addReadhistory(baseRequest);
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 删除历史纪录 delReadhistory
     **/
    @ResponseBody
    @RequestMapping(value = "delReadhistory", method = RequestMethod.POST)
    public BaseRespose delReadhistory(@RequestBody BaseRequest baseRequest) {
        BaseRespose baseRespose = bookService.delReadhistory(baseRequest);
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 查询我的收藏 selectCollectionList
     **/
    @ResponseBody
    @RequestMapping(value = "selectCollectionList", method = RequestMethod.POST)
    public BaseRespose selectCollectionList(@RequestBody BaseRequest baseRequest) {
        BaseRespose baseRespose = bookService.selectCollectionList(baseRequest);
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 添加收藏 addCollection
     **/
    @ResponseBody
    @RequestMapping(value = "addCollection", method = RequestMethod.POST)
    public BaseRespose addCollection(@RequestBody BaseRequest baseRequest) {
        BaseRespose baseRespose = bookService.addCollection(baseRequest);
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 删除收藏 deleteCollection
     **/
    @ResponseBody
    @RequestMapping(value = "deleteCollection", method = RequestMethod.POST)
    public BaseRespose deleteCollection(@RequestBody BaseRequest baseRequest) {
        BaseRespose baseRespose = bookService.deleteCollection(baseRequest);
        return baseRespose;
    }


    public static void main(String[] args) {
        BaseRequest baseRequest = new BaseRequest();
        baseRequest.setToken("xx");
        baseRequest.setUserId(123);
        BookinformationCustom bookinformationCustom = new BookinformationCustom();
        bookinformationCustom.setBookname("斗破苍穹");
        bookinformationCustom.setAuthor("天蚕土豆");
        bookinformationCustom.setIntroduction("《斗破苍穹》是一本连载于起点中文网的古装玄幻小说，作者是起点白金作家天蚕土豆（李虎），已完结。这里是属于斗气的世界，没有花俏艳丽的魔法，有的，仅仅是繁衍到巅峰的斗气...");
        bookinformationCustom.setBookurl("https://doupocangqiong1.com/1/1.html");
        bookinformationCustom.setMainlevelid(2);
        bookinformationCustom.setMainlevelname("斗气");
        bookinformationCustom.setSecondlevelid(1);
        bookinformationCustom.setSecondlevelname("玄幻");
        bookinformationCustom.setCoverurl("http://wokezhineng.oss-cn-huhehaote.aliyuncs.com/image/20190531/2ba30ba6-4735-4946-996d-5da535d20deb.jpg");
        bookinformationCustom.setCreateuserid(1);
        List<String> list = new ArrayList<>();
        list.add("武斗");
        list.add("斗气");
        list.add("爱情");
        bookinformationCustom.setLabelNames(list);
        baseRequest.setRequestString(bookinformationCustom);
    }
}
